<?php

class Application_Model_ConsumoDatacenter extends Sgit_Model
{  
    protected $_name = 'consumo_datacenter';
    protected $_primary = 'id';


    function getConsumoMes($id_zona,$fecha=null,$anio=null,$mes=null)
    {
   
        if($fecha){
            $fecha= new Zend_Date($fecha,Zend_Date::ISO_8601);
            $mes=$fecha->get('M');
            $anio=$fecha->get('yyyy');
        }

   
   
        $select = $this->getAdapter()->select();
        $select->from(array($this->_name),array('importe'=>new Zend_Db_Expr('SUM(importe)')))
        ->joinLeft('proveedores', 'proveedores.id = consumo_datacenter.id_proveedor',array(''))
        ->where("id_zona = ?",$id_zona)
        ->where("mes = ?",$mes)
        ->where("anno = ?",$anio)
        ->group(array('mes','anno'));
        
        return $this->getAdapter()->fetchOne($select);

    
    }
    
    function getMes($id_zona,$fecha=null,$anio=null,$mes=null)
    {
   
        if($fecha){
            $fecha= new Zend_Date($fecha,Zend_Date::ISO_8601);
            $mes=$fecha->get('M');
            $anio=$fecha->get('yyyy');
        }

   
   
        $select = $this->getAdapter()->select();
        $select->from(array($this->_name),array('importe'=>new Zend_Db_Expr('SUM(importe)'),'consumo'=>new Zend_Db_Expr('SUM(consumo)')))
        ->joinLeft('proveedores', 'proveedores.id = consumo_datacenter.id_proveedor',array(''))
        ->where("id_zona = ?",$id_zona,INTEGER)
        ->where("mes = ?",$mes,INTEGER)
        ->where("anno = ?",$anio,INTEGER)
        ->group(array('mes','anno'));
        
        
        return $this->getAdapter()->fetchRow($select);
        
        

    
    }

   
} 




